﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MokkAnnotator.MkaDrawTools;

namespace MokkAnnotator
{
    public partial class TextFormat : UserControl
    {
        private Point MouseDownLocation;// using to move strip container

        private int _size;//Comment size

        public int CommentSize
        {
            get { return _size; }
            set { _size = value; }
        }
        private String _font; //Comment font

        public String CommentFont
        {
            get { return _font; }
            set { _font = value; }
        }

        private String _color; ////Comment Color

        public String CommentColor
        {
            get { return _color; }
            set { _color = value; }
        }

        private String _typetext; //Comment type: Bold, Italic, Underline

        public String CommentTypeText
        {
            get { return _typetext; }
            set { _typetext = value; }
        }


        public TextFormat()
        {
            InitializeComponent();
        }

        private void tstpContainerCommentControl_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                MouseDownLocation = e.Location;
            }

        }
        private void tstpContainerCommentControl_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                this.BringToFront();
                Cursor.Current = Cursors.SizeAll;
                this.Location = new Point(e.X + this.Location.X - MouseDownLocation.X, e.Y + this.Location.Y - MouseDownLocation.Y);
            }
        }

        private void tstpContainerCommentControl_MouseUp(object sender, MouseEventArgs e)
        {
            Cursor.Current = Cursors.Arrow;
        }

        private void tspBold_Click(object sender, EventArgs e)
        {
            MkaDocument parent = this.Parent as MkaDocument;
            RichTextBox lastTextBox = parent.LastTextBoxFocused;
            if (parent.LastTextBoxFocused != null)
            {
                lastTextBox.Focus();
                lastTextBox.SelectionStart = parent.StartPositionSelectedText;
                lastTextBox.SelectionLength = parent.LengthSelectedText;
                Font Ifont = new Font(lastTextBox.SelectionFont, FontStyle.Bold);
                Font rfont = new Font(lastTextBox.SelectionFont, FontStyle.Regular);
                if (lastTextBox.SelectionFont.Bold)
                {
                    lastTextBox.SelectionFont = rfont;
                }
                else
                {
                    lastTextBox.SelectionFont = Ifont;
                }
            }
        }

        private void tstpCbSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            MkaDocument parent = this.Parent as MkaDocument;
            RichTextBox lastTextBox = parent.LastTextBoxFocused;
            if (lastTextBox != null)
            {
                lastTextBox.Focus();
                lastTextBox.SelectionStart = parent.StartPositionSelectedText;
                lastTextBox.SelectionLength = parent.LengthSelectedText;
                lastTextBox.SelectionFont = new Font(tstpCbFont.SelectedItem.ToString(),
                int.Parse(tstpCbSize.SelectedItem.ToString()), lastTextBox.SelectionFont.Style);
            }
        }

        private void tstpCbColor_SelectedIndexChanged(object sender, EventArgs e)
        {
            MkaDocument parent = this.Parent as MkaDocument;
            RichTextBox lastTextBox = parent.LastTextBoxFocused;
            if (lastTextBox != null)
            {
                lastTextBox.Focus();
                lastTextBox.SelectionStart = parent.StartPositionSelectedText;
                lastTextBox.SelectionLength = parent.LengthSelectedText;
                lastTextBox.SelectionColor = Color.FromName(tstpCbColor.SelectedItem.ToString());
            }
        }

    }
}
